package me.zhengjie.minbearwcs.dao.stock.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import me.zhengjie.minbearwcs.dao.stock.inf.MaterialTypeDao;
import me.zhengjie.minbearwcs.entity.Mapper.stock.MaterialTypeMapper;
import me.zhengjie.minbearwcs.entity.PO.wcs.stock.MaterialType;

@Repository
@RequiredArgsConstructor
public class MaterialTypeDaoImpl implements MaterialTypeDao {

    private final MaterialTypeMapper mapper;

    @Override
    public MaterialType selectByMaterialCode(String materialCode) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(MaterialType::getMaterialCode, materialCode)
                .oneOpt()
                .orElse(null);
    }

    @Override
    public boolean insert(MaterialType materialType) {
        return mapper.insert(materialType) == 1;
    }

    @Override
    public boolean delete() {
        return mapper.delete(new QueryWrapper<MaterialType>()) == 1;
    }

    @Override
    public boolean update(MaterialType materialType) {
        return mapper.updateById(materialType) == 1;
    }

    @Override
    public Long getCount() {
        return new LambdaQueryChainWrapper<>(mapper)
                .count();
    }
}
